package com.hz.web.controller;

import com.alibaba.fastjson.JSON;
import com.hz.web.entity.Notify;
import com.hz.web.entity.Sheet;
import com.hz.web.service.NotifyService;
import com.hz.web.service.SheetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * Created by kaddddd on 2018/5/15 0015.
 */
@Controller
public class NotifyController {
    @Autowired
    NotifyService notifyService;

    @RequestMapping("/selectNotifyList")
    public @ResponseBody String selectNotifyList(ModelMap model){
        List<Notify> list = notifyService.selectNotifyList();
        String sheetList = JSON.toJSONString(list);
        return sheetList;
    }

    @RequestMapping("/addNotify")
    public void addNotify(HttpServletRequest request){
        String title = request.getParameter("title");
        String type = request.getParameter("type");
        String content = request.getParameter("content");
        Notify notify = new Notify();
        notify.setTitle(title);
        notify.setType(type);
        notify.setContent(content);
        Date createDate =new Date();
        notify.setCreateDate(createDate);
        notifyService.addNotify(notify);
    }
}
